<?php

class Plugin
{

	private static $init = false;

	function __construct() { }

	public static function &load($plugin)
	{
		$argv = func_get_args();
		$argc = func_num_args();

		$plugin = ucwords($plugin);
		$plugin_real = str_replace(" ","",$plugin);
		$class_name = "Plugin".$plugin_real;

		if (!class_exists($class_name,true))
		{
			throw new Exception("Plugin '".$plugin_real."' does not exist.");
		}

		$new_plugin = new $class_name();
		if (!($new_plugin instanceof APlugin))
			throw new Exception("Plugin request for '".$plugin_real."' caused loading of '".$class_name."', which is not a valid plugin.");

		$new_plugin->init($plugin_real);
		array_shift($argv);

		call_user_func_array(array($new_plugin,"load"),$argv);
		return $new_plugin;
	}

}

?>